﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
using ModuleDALCore;

namespace DAL
{
	public class TIENSUBENHNHANDAO:DALBase
	{
		public TIENSUBENHNHANDAO()
		{
			this.OpenConnect();
		}
		private DataTable dt;
		private string _SpName;

		public string SpName
		{
			get { return "SPTIENSUBENH"; }
			set { _SpName = value; }
		}
		public DataTable GetListTSB()
		{
			dt = new DataTable();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new TIENSUBENHNHAN(), null), ConvertClassToArray.GetValues(new TIENSUBENHNHAN(), 0));
				return dt;
			}
			catch { throw new InvalidExpressionException("Msg1: Can't list TSB"); }
		}
		public List<TIENSUBENHNHAN> GetListTSBs()
		{
			dt = new DataTable();
			List<TIENSUBENHNHAN> ds = new List<TIENSUBENHNHAN>();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new TIENSUBENHNHAN(), null), ConvertClassToArray.GetValues(new TIENSUBENHNHAN(), 0));
				ds = (List<TIENSUBENHNHAN>)ConvertDatatableToList.ConvertTo<TIENSUBENHNHAN>(dt);
			}
			catch { throw new InvalidExpressionException("Msg1: Can't list TSB"); }
			return ds;
		}
		public List<TIENSUBENHNHAN> GETTIENSUTHEOBN(TIENSUBENHNHAN ts)
		{
			dt = new DataTable();
			List<TIENSUBENHNHAN> ds = new List<TIENSUBENHNHAN>();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(ts, null), ConvertClassToArray.GetValues(ts, 4));
				ds = (List<TIENSUBENHNHAN>)ConvertDatatableToList.ConvertTo<TIENSUBENHNHAN>(dt);
			}
			catch { throw new InvalidExpressionException("Msg1: Can't list TSB folow bn"); }
			return ds;
		}
		public bool INSERT(TIENSUBENHNHAN cv)
		{

			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 2)) == 1);

			}
			catch { throw new InvalidExpressionException("Msg1: Can't Insert new TSB"); }
		}
		public bool UPDATE(TIENSUBENHNHAN cv)
		{

			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 3)) == 1);

			}
			catch { throw new InvalidExpressionException("Msg1: Can't Update  TSB"); }
		}
		public bool DELETE(TIENSUBENHNHAN cv)
		{

			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 4)) == 1);

			}
			catch { throw new InvalidExpressionException("Msg1: Can't Delete  TSB"); }
		}
	}
}
